<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<div style="padding: 10px;">
	<form class="op-form" id="editForm" name="editForm" method="post">
		<input type="hidden" name="id" value="${userEnt.id }">
		<table>
			<tr>
				<td>姓名:</td>
				<td>
					<input class="easyui-validatebox" name="name" required="true" validType="chinese;length[2,12]" value="${userEnt.name }">
				</td>
			</tr>
			<tr>
				<td>性别:</td>
				<td>
					<select id="sex" name="sex" class="easyui-combobox" required="true" style="width: 206px;">
						<option value="0">女</option>
						<option value="1">男</option>
					</select>
				</td>
			</tr>
			<tr>
				<td>账户:</td>
				<td>
					<input class="easyui-validatebox" name="code" required="true" validType="length[2,20]" value="${userEnt.code }">
				</td>
			</tr>
			<tr>
				<td>联系电话:</td>
				<td>
					<input class="easyui-validatebox" name="phone" required="false" validType="telephone" value="${userEnt.phone }">
				</td>
			</tr>
			<tr>
				<td>家庭住址:</td>
				<td>
					<input class="easyui-validatebox" name="address" required="false" validType="length[2,50]" value="${userEnt.address }">
				</td>
			</tr>
			<tr>
				<td>手机:</td>
				<td>
					<input class="easyui-validatebox" name="mobile" required="true" validType="mobile" value="${userEnt.mobile }">
				</td>
			</tr>
			<tr>
				<td>Email:</td>
				<td>
					<input class="easyui-validatebox" name="email" required="false" validType="email" value="${userEnt.email }">
				</td>
			</tr>
			<tr>
				<td>角色:</td>
				<td>
					<select id="roleid" name="roleid" class="easyui-combobox" required="true" style="width: 206px;"></select>
				</td>
			</tr>
			<tr>
				<td>个人说明:</td>
				<td>
					<textarea class="easyui-validatebox" name="others" required="false" validType="length[0,100]" style="height:100px;">${userEnt.others }</textarea>
				</td>
			</tr>
			<tr>
				<td>
					<a href="#" class="easyui-linkbutton" icon="icon-ok" onclick="$('#editForm').submit()">提交</a>
				</td>
				<td>
					<a href="#" class="easyui-linkbutton" icon="icon-cancel" onclick="editForm.reset()">重置</a>
					<a href="#" class="easyui-linkbutton" icon="icon-redo" onclick="$('#dataGrid').show();$('#opPanel').panel('close');">返回</a>
				</td>
			</tr>
		</table>
	</form>
</div>

<script type="text/javascript">

	$(document).ready(function(){
		// 性别默认值
		// $('#sex option[value='+ ${userEnt.sex} +']').attr('selected', true);
		//$("#sex").combobox();
		//$("#sex").combobox('setValue', '${userEnt.sex}');
		$('#sex').combobox({
		    url: 'user.action?command=getSexs&sex=${userEnt.sex}',
		    valueField: 'value',
		    textField: 'name',
		    required: true
		});
		
		$('#roleid').combobox({
		    url: 'user.action?command=getRoles&roleid=${userEnt.role.id}',
		    valueField: 'id',
		    textField: 'name'
		});
	
		$('#editForm').form({
			onSubmit: function(){
				if($(this).form('validate')){
					ajaxEdit();
				}else{
					return false;
				}
			}
		});
	});
	
	function ajaxEdit(){
		var actionURL = "user.action?command=update";
		var params = jQuery("#editForm").dataForAjax().data;
		
		jQuery.ajax({
			url: actionURL,
			type: "post",
			cache: false,
			data: params,
			success: function(result){
				if("true" == result){
					$.messager.alert("友情提示", "您的操作成功!", "info", function(){
						clearSels();
						setBtn(true);
						$('#tt').datagrid('reload');
						$("#dataGrid").show();
						$("#opPanel").panel("close");
					});
				}else{
					$.messager.alert("友情提示", "您的操作失败!", "error");
				}
			}
		});
	}
	
</script>